package com.missilike.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.missilike.biz.IMilTradeRecordService;
import com.missilike.core.result.CommonResult;
import com.missilike.core.utils.ResultUtils;
import com.missilike.repository.entity.MilTradeRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author kin
 * @since 2019-01-08
 */
@RestController
@RequestMapping("/api/mil/trade_record")
public class MilTradeRecordController {

    private final IMilTradeRecordService milTradeRecordService;

    @Autowired
    public MilTradeRecordController(IMilTradeRecordService milTradeRecordService) {
        this.milTradeRecordService = milTradeRecordService;
    }

    @RequestMapping(value = "page", method = RequestMethod.GET)
    public CommonResult list(@RequestParam(value = "pageNum", required = false, defaultValue = "1") int pageNum,
                             @RequestParam(value = "pageSize", required = false, defaultValue = "20") int pageSize,
                             @RequestParam(value = "account", required = false, defaultValue = "") String account) {
        IPage<MilTradeRecord> page = milTradeRecordService.page(new Page<>(pageNum, pageSize),new QueryWrapper<MilTradeRecord>()
                .lambda()
                .likeRight(MilTradeRecord::getAccountId,account)
        );
        return ResultUtils.ok(page);
    }
}

